package com.ruoyi.production.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.Circuit;
import com.ruoyi.production.service.ICircuitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品工艺线路Controller
 * 
 * @author admin
 * @date 2024-08-02
 */
@Api
@RestController
@RequestMapping("/production/circuit")
public class CircuitController extends BaseController
{
    @Autowired
    private ICircuitService circuitService;

    /**
     * 查询产品工艺线路列表
     */
    @PreAuthorize("@ss.hasPermi('production:circuit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Circuit circuit)
    {
        startPage();
        List<Circuit> list = circuitService.selectCircuitList(circuit);
        return getDataTable(list);
    }

    /**
     * 导出产品工艺线路列表
     */
    @PreAuthorize("@ss.hasPermi('production:circuit:export')")
    @Log(title = "产品工艺线路", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Circuit circuit)
    {
        List<Circuit> list = circuitService.selectCircuitList(circuit);
        ExcelUtil<Circuit> util = new ExcelUtil<Circuit>(Circuit.class);
        util.exportExcel(response, list, "产品工艺线路数据");
    }

    /**
     * 获取产品工艺线路详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:circuit:query')")
    @GetMapping(value = "/{circuitId}")
    public AjaxResult getInfo(@PathVariable("circuitId") Long circuitId)
    {
        return success(circuitService.selectCircuitByCircuitId(circuitId));
    }

    /**
     * 新增产品工艺线路
     */
    @PreAuthorize("@ss.hasPermi('production:circuit:add')")
    @Log(title = "产品工艺线路", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Circuit circuit)
    {
        return toAjax(circuitService.insertCircuit(circuit));
    }

    /**
     * 修改产品工艺线路
     */
    @PreAuthorize("@ss.hasPermi('production:circuit:edit')")
    @Log(title = "产品工艺线路", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Circuit circuit)
    {
        return toAjax(circuitService.updateCircuit(circuit));
    }

    /**
     * 删除产品工艺线路
     */
    @PreAuthorize("@ss.hasPermi('production:circuit:remove')")
    @Log(title = "产品工艺线路", businessType = BusinessType.DELETE)
	@DeleteMapping("/{circuitIds}")
    public AjaxResult remove(@PathVariable Long[] circuitIds)
    {
        return toAjax(circuitService.deleteCircuitByCircuitIds(circuitIds));
    }
}
